import axios from "../../utils/axios";

let api = `${baseApi}currency`;
/**
 * @method getPosition 获取 省 市 区 位置
 * @param id 父级id 全部省 => 0 查询市 => 省id ..
 * @return axios
 */
export const getPosition = function (params) {
    return axios.get(`${api}/parentIdList/${params}`);
};

/**
 * @method getLoginPerson 存放登录信息
 * @param
 * @return axios
 */
export const getLoginPerson = function (params) {
    // return axios.post(`${api}/getLoginPerson`, params);
    return axios.post(`${ccmsApi}/getLoginPerson`, params);
};

/**
 * @method logout 注销登录
 * @param
 * @return axios
 */
export const logout = function () {
    return axios.get(`${api}/logout`);
};

/**
 * @method Login 登录
 * @param
 * @return axios
 */
export const Login = function (params) {
    return axios.post(`${loginApi}`, params);
};

/**
 * @method Login 登录
 * @param
 * @return axios
 */
export const GetCcmsUserInfo = function (params) {
    // return axios.get(`${ccmsApi}ccms/rbac/user`);
    return axios.get(`${ccmsApi}user`);
};

/**
 * @method   UploadImage 上传多张图片
 * @param
 * @return axios
 */
export const UploadImage = function (params) {
    axios.defaults.headers.common["Content-Type"] = "multipart/form-data";
    return axios.post(`${ccmsApi}ccms/fileupload/file/uploadImage`, params);
};

/**
 * @method   userGroups 查询当前登录用户权限内的用户列表信息
 * @param
 * @return axios
 */
export const userGroups = function (params) {
    return axios.get(`${ccmsApi}ccms/rbac/userGroups/list`);
};

/**
 * @method   loginUser 获取所属组织的数据
 * @param
 * @return axios
 */
export const loginUser = function (params) {
    // return axios.get(`${ccmsApi}ccms/home/loginUser`);
    return axios.get(`${ccmsApi}/loginUser`);
};

/**
 * @method   employee 根据员工Id查询员工详情信息
 * @param
 * @return axios
 */
export const employee = function (params) {
    return axios.get(`${ccmsApi}ccms/org/employee/${params}`);
};

/**
 * 解耦合 根据名称来变成对应的 ID
 */
export const selectNameToId = function (params) {
    switch (params) {
        //所属区域
        case "area":
            params = "001";
            break;
        //房源类型
        case "housingType":
            params = "002";
            break;
        //物业
        case "property":
            params = "003";
            break;
        //房间朝向
        case "facing":
            params = "004";
            break;
        //权利人
        case "power":
            params = "005";
            break;
        //房屋类型
        case "houseType":
            params = "006";
            break;
        //房间户型
        case "roomType":
            params = "007";
            break;
        //房间状态
        case "roomState":
            params = "008";
            break;
        //出租人
        case "lessor":
            params = "009";
            break;
        //合同用途
        case "contractPurpose":
            params = "010";
            break;
        //房间用途
        case "roomUse":
            params = "011";
            break;
        //配套设施
        case "supportingFacilities":
            params = "012";
            break;
        //职业
        case "occupation":
            params = "013";
            break;
        //工单type
        case "workOrder":
            params = "014";
            break;
        //出租方式
        case "rentalMode":
            params = "015";
            break;
        //管理处
        case "adminOffice":
            params = "016";
            break;
        //工单类型
        case "equipment":
            params = "019";
            break;
    }
    return params;
};

/**
 * @method   getOneAll 根据编码查询所有一级信息
 * @param
 * @return axios
 */
export const getOneAll = function (params) {
    return axios.get(`${api}/getOneAll/` + params);
};

/**
 * @method   getAllByTwo 根据一级关联id查询二级信息
 * @param
 * @return axios
 */
export const getAllByTwo = function (params) {
    return axios.get(`${api}/getAllByTwo/` + params);
};

/**
 * @method   getTwoAll 根据一级编码查询所有二级信息
 * @param
 * @return axios
 */
export const getTwoAll = function (params) {
    return axios.get(`${api}/getTwoAll/` + params);
};

/**
 * @method   app 获取中台app
 * @param
 * @return axios
 */
export const getApp = function () {
    // return axios.get(`${ccmsApi}ccms/home/app`);
    return axios.get(`${ccmsApi}app`);
};

/**
 * @method   adminLogin 总登录接口
 * @param
 * @return axios
 */
export const adminLogin = function (params) {
    return axios.post(`${api}/adminLogin`, params);
};

/**
 * @method  获取中台菜单权限
 * @param
 * @return axios
 */
export const getMenu = function (params) {
    // return axios.get(`${ccmsApi}ccms/home/menu`, { params: params });
    return axios.get(`${ccmsApi}menu`, { params: params });
};


/**
 * @method  获取管理处
 * @param
 * @return axios
 */
export const enterprise = function (params) {
    // return axios.get(`${ccmsApi}ccms/org/enterprise/${params}`);
    return axios.get(`${ccmsApi}enterprise/${params}`);
};

/**
 * base:image 转 formData
 */
export const baseImgToFormData = function (params) {
    let formData = new FormData();
    params.forEach(item => {
        if (item.indexOf("data:image") === 0) {
            var bytes = window.atob(item.split(",")[1]);
            var array = [];
            for (var i = 0; i < bytes.length; i++) {
                array.push(bytes.charCodeAt(i));
            }
            var blob = new Blob([new Uint8Array(array)], { type: "image/jpeg" });
            formData.append("file", blob);
        }
    });
    return formData;
};

//获取user
export const getUserInfo = function () {
    if (localStorage.getItem("userInfo")) {
        return JSON.parse(localStorage.getItem("userInfo"));
    } else {
        return undefined;
    }
};
